/*
 * Created by JFormDesigner on Tue Jul 02 03:09:34 CST 2024
 */

package scct.hys.ui;

import scct.hys.dao.ScreeningDao;
import scct.hys.model.Movie;
import scct.hys.model.Screening;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author 26984
 */
public class DlgScreeningAdd extends JDialog {
    int id;
    public DlgScreeningAdd(Window owner,int id) {
        super(owner);
        initComponents();
        this.id=id;
    }

    private void btnAdd(ActionEvent e) {
        // TODO add your code here

        String name=txtCinameName.getText();
        String startTime=txtStartTime.getText();
        String price=txtPrice.getText();
        String type=txtType.getText();
        ScreeningDao screeningDao=new ScreeningDao();

        if(screeningDao.addScreening(name,startTime,price,type)){
//            JOptionPane.showMessageDialog(this,"添加成功");
        }
        this.dispose();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - 韩月生
        label1 = new JLabel();
        txtCinameName = new JTextField();
        label2 = new JLabel();
        txtStartTime = new JTextField();
        label3 = new JLabel();
        txtPrice = new JTextField();
        label4 = new JLabel();
        txtType = new JTextField();
        btnAdd = new JButton();
        btnCancel = new JButton();

        //======== this ========
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u7535\u5f71\u540d\u79f0");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(70, 40), label1.getPreferredSize()));
        contentPane.add(txtCinameName);
        txtCinameName.setBounds(155, 35, 155, txtCinameName.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u4e0a\u6620\u65f6\u95f4");
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(70, 75), label2.getPreferredSize()));
        contentPane.add(txtStartTime);
        txtStartTime.setBounds(155, 70, 155, txtStartTime.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u4ef7\u683c");
        contentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(70, 115), label3.getPreferredSize()));
        contentPane.add(txtPrice);
        txtPrice.setBounds(155, 110, 155, txtPrice.getPreferredSize().height);

        //---- label4 ----
        label4.setText("\u7535\u5f71\u7c7b\u578b");
        contentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(70, 150), label4.getPreferredSize()));
        contentPane.add(txtType);
        txtType.setBounds(155, 145, 155, txtType.getPreferredSize().height);

        //---- btnAdd ----
        btnAdd.setText("\u786e\u5b9a\u6dfb\u52a0");
        btnAdd.addActionListener(e -> btnAdd(e));
        contentPane.add(btnAdd);
        btnAdd.setBounds(new Rectangle(new Point(70, 200), btnAdd.getPreferredSize()));

        //---- btnCancel ----
        btnCancel.setText("\u53d6\u6d88");
        contentPane.add(btnCancel);
        btnCancel.setBounds(new Rectangle(new Point(250, 200), btnCancel.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(400, 300);
        setLocationRelativeTo(null);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - 韩月生
    private JLabel label1;
    private JTextField txtCinameName;
    private JLabel label2;
    private JTextField txtStartTime;
    private JLabel label3;
    private JTextField txtPrice;
    private JLabel label4;
    private JTextField txtType;
    private JButton btnAdd;
    private JButton btnCancel;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
